<!DOCTYPE html>
<html>
<head>
<title>管理系统--登录</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<meta name="author" content="Vincent Garreau" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" media="screen" href="resources/css/style.css">
<link rel="stylesheet" type="text/css" href="resources/css/reset.css"/>
<script type="text/javascript" src="resources/js/jquery.min.js"></script>
<script type="text/javascript" src="resources/js/base64.js"></script>

</head>
<body>
	<div id="particles-js">
		<div class="wl_topbar">
			<img src="resources/images/prevail.gif" />
		</div>
		<div class="login">
			<div class="login-top">
				用户登陆
			</div>
			<div class="login-center clearfix">
				<div class="login-center-img"><img src="resources/images/name.png"/></div>
				<div class="login-center-input">
					<input id="username" type="text" name="" value="" placeholder="请输入您的用户名" onfocus="this.placeholder=''" onblur="this.placeholder='请输入您的用户名'"/>
					<div class="login-center-input-text">用户名</div>
				</div>
			</div>
			<div class="login-center clearfix">
				<div class="login-center-img"><img src="resources/images/password.png"/></div>
				<div class="login-center-input">
					<input id="lg-psw" type="password" name=""value="" placeholder="请输入您的密码" onfocus="this.placeholder=''" onblur="this.placeholder='请输入您的密码'"/>
					<div class="login-center-input-text">密码</div>
				</div>
			</div>
			<div class="login-button">
				登陆
			</div>
		</div>
		<div class="sk-rotating-plane"></div>
</div>
<!-- scripts -->
<script src="resources/js/particles.min.js"></script>
<script src="resources/js/app.js"></script>
<script src="resources/layui/layui.all.js"></script>
<script type="text/javascript">
	$(function () {
	    //判断一下当前是不是最顶层，如果不是，则做一下顶层页面重定向
	    if (window != top) {
	        top.location.href = location.href;
	    }
	});

	$('#lg-psw').bind('keypress',function(event){
		 
	    if(event.keyCode == "13")    	
	    {	
	    	submitForm();	
	    }
	
	});
	function hasClass(elem, cls) {
	  cls = cls || '';
	  if (cls.replace(/\s/g, '').length == 0) return false; //当cls没有参数时，返回false
	  return new RegExp(' ' + cls + ' ').test(' ' + elem.className + ' ');
	}
	 
	function addClass(ele, cls) {
	  if (!hasClass(ele, cls)) {
	    ele.className = ele.className == '' ? cls : ele.className + ' ' + cls;
	  }
	}
	 
	function removeClass(ele, cls) {
	  if (hasClass(ele, cls)) {
	    var newClass = ' ' + ele.className.replace(/[\t\r\n]/g, '') + ' ';
	    while (newClass.indexOf(' ' + cls + ' ') >= 0) {
	      newClass = newClass.replace(' ' + cls + ' ', ' ');
	    }
	    ele.className = newClass.replace(/^\s+|\s+$/g, '');
	  }
	}
	
	function submitForm(){
		//debugger;
		var defaultstr = $("#lg-psw").val();
		var newpsw = $.base64.encode(defaultstr);
		//var repsw = $.base64.decode(newpsw);
		var datastr = '{"username":"'+$("#username").val()+'","password":"' +  $.base64.encode(defaultstr) + '"}';
		$.ajax({
			type:"post",
			contentType: "application/json;charset=UTF-8",
			url: "login.do?",
			async:false,
			data:datastr,
	     	dataType:"json",
	        success: function(msg) {    //数据提交成功时返回数据
				if(msg.status == "1"){
					var flag = window.location.href.lastIndexOf("/");
					location.href = window.location.href.substring(0,flag);
				}else{
					layer.msg(msg.desc,{icon: 2, time:2000});	
				}
	        },
	        error : function(e){
	            alert(e.status);
	            alert(e.responseText);
	        }

		});
		/*$('#ff').form('submit',{   
		    success: function(data){    	
		    	location.reload();           
		    }
		});*/
	}
		
	document.querySelector(".login-button").onclick = function(){
			addClass(document.querySelector(".login"), "active")
			setTimeout(function(){
				addClass(document.querySelector(".sk-rotating-plane"), "active")
				document.querySelector(".login").style.display = "none"
			},800);
			
			setTimeout(function(){
				removeClass(document.querySelector(".login"), "active")
				removeClass(document.querySelector(".sk-rotating-plane"), "active")
				document.querySelector(".login").style.display = "block"
				//alert("登录成功")
				
			},3000);
			
			submitForm();
	}
</script>
</body>
	